package solution;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2023-01-18
 * Time: 20:41
 */
public class Solution7 {
    public static void main(String[] args) {
        System.out.println(toLowerCase("dasA"));
        System.out.println(toUpperCase("sddf"));
    }

    public static String toLowerCase(String s) {
        int sl = s.length();
        char ch;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < sl; i++) {
            ch = s.charAt(i);
            if (ch >= 65 && ch <= 90) {
                ch |= 32;//通过二进制的位数比较实现相加的效果，且速度更快
            }
            sb.append(ch);
        }
        return sb.toString();
    }

    public static String toUpperCase(String s) {
        int sl = s.length();
        char ch;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < sl; i++) {
            ch = s.charAt(i);
            if (ch >= 97 && ch <= 122) {
                ch ^= 32;//通过二进制的位数比较实现相加的效果，且速度更快
            }
            sb.append(ch);
        }
        return sb.toString();
    }

}
